#include "ADUAppDelegate.h"
#include "ADUGamePlayScene.h"
#include "ADUConstant.h"
USING_NS_CC;

AppDelegate::AppDelegate() {

}

AppDelegate::~AppDelegate() 
{
}

bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLView::create("UGLY DUCKLING");
        director->setOpenGLView(glview);
    }
#if 1
    auto screenSize = glview->getFrameSize();

    auto designSize = Size(480, 320);

    
    if (screenSize.height > 320)
    {
        auto resourceSize = Size(1920, 1080);
        director->setContentScaleFactor(resourceSize.height/designSize.height);
        PTM_RATIO /= CC_CONTENT_SCALE_FACTOR();
    }
    else
    {

    }
    

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
    // a bug in DirectX 11 level9-x on the device prevents ResolutionPolicy::NO_BORDER from working correctly
    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL);
#else
    glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::EXACT_FIT);
#endif

#endif
    director->setAnimationInterval(1.0 / 60);

    // Load resource
    // load the Sprite Sheet
    SpriteFrameCache* spritecache = SpriteFrameCache::getInstance();
    // the .plist file can be generated with any of the tools mentioned below
    spritecache->addSpriteFramesWithFile("resources.plist","resources.png");

    // create a scene. it's an autorelease object
    GameManager::getInstance()->RunScene(SPLASH_SCENE);

    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground() {
    Director::getInstance()->stopAnimation();

    // if you use SimpleAudioEngine, it must be pause
    // SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
    CocosDenshion::SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
    Director::getInstance()->startAnimation();

    // if you use SimpleAudioEngine, it must resume here
    // SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
    CocosDenshion::SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
}
